<?php
class Core_Component_System_Business_Logging_Db{

	public function logAccess($type, $id, array $parameter = array()){
		$model = App::getModel('logging/access');
		$model->setIpAddress($_SERVER['REMOTE_ADDR'])
			   ->setSourceType($type)
			   ->setSourceId($id)
			   ->setAccessTime(date('Y-m-d H:i:s'))
			   ->setParameter($parameter)
			   ->setReferer(isset($_SERVER['HTTP_REFERER'])? $_SERVER['HTTP_REFERER']: '')
			   ->save();
	}
	
	public function logRequest(){
		$router =  $GLOBALS[RC]->getRouter();
		$model = App::getModel('logging/request');
		$model->setIpAddress($_SERVER['REMOTE_ADDR'])
			   ->setHostName($_SERVER['HTTP_HOST'])
			   ->setUrl($_SERVER['REQUEST_URI'])
			   ->setDomain($router->getDomainName())
			   ->setComponent($router->getComponent())
			   ->setController($router->getController())
			   ->setAction($router->getAction())
			   ->setAccessTime(date('Y-m-d H:i:s'))
			   ->setParameter(base64_encode(serialize($GLOBALS[ORP])))
			   ->setReferer(isset($_SERVER['HTTP_REFERER'])? $_SERVER['HTTP_REFERER']: '')
			   ->setUserName($GLOBALS[RC]->getIdentity()->getName())
			   ->save();		
	}
}